package com.jiangsong.batch;

import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.ChunkListener;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ProductChunkListener implements ChunkListener {



    @Override
    public void beforeChunk(ChunkContext chunkContext) {
        log.info("外层chunk,之前");
//        chunkContext.getStepContext().getStepExecution().getExecutionContext()
//                .put("testKey", "testValue");

    }

    @Override
    public void afterChunk(ChunkContext chunkContext) {
        Object o = chunkContext.getStepContext().getStepExecution().getExecutionContext()
                .get("testKey");
        Object o1 = chunkContext.getStepContext().getStepExecution().getExecutionContext()
                .get("testKey1");
        log.info("外层chunk, o:{}, o1:{}", o, o1);

    }

    @Override
    public void afterChunkError(ChunkContext chunkContext) {

    }
}
